﻿using PenguinForce.Collisions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;

namespace PenguinForce.Entities
{
    public class Igloo : ICollisionEntity
    {
        #region Constructors

        public Igloo(Texture2D texture)
        {
            this.Texture = texture;
            this.Position = Vector2.Zero;
            this.Origin = new Vector2(this.Texture.Width / 2.0f, this.Texture.Height / 2.0f);
        }

        #endregion

        #region Properties

        public Texture2D Texture { get; private set; }

        public Vector2 Position { get; set; }

        public BoundingSphere Bounds
        {
            get
            {
                return new BoundingSphere(new Vector3(Position, 0), 70.0f);
            }
        }

        private Vector2 Origin { get; set; }

        #endregion

        #region Methods

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(this.Texture, this.Position, null, Color.White, 0.0f, this.Origin, 1.0f, SpriteEffects.None, 0.5f);
        }

        /// <summary>
        /// If a penguin touches the igloo, remove it from the level (this is a good thing).
        /// </summary>
        public void TestIntersections()
        {
            foreach (Penguin penguin in new List<Penguin>(CollisionManager.Instance.Penguins.flock))
            {
                if (penguin.Bounds.Intersects(this.Bounds))
                {
                    CollisionManager.Instance.Penguins.Kill(penguin);
                    CollisionManager.Instance.GetCurrentLevel().m_parPenguins--;
                }
            }
        }

        #endregion
    }
}